package com.example.demo02.form;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lq on 16/01/19.
 */

public class BaseForm {
    //dev 999

    private String enabled;
    private String keyword;
    // de v  new new
    private String actiontype;//1新增 2修改
    private Boolean checkflag;//1确认
    //当前页码
    private int pageNum;
    //dev new 2
    //dev new 3
    //dev new 4
    private String sortcolumn;
    private String sortorder;
    private String orderBy;

    private int draw;
    private int start = 0;//recordno
    private int length;//pagesize 一个的条数

    private int totalOffset=0;
    private long recordTotal = 0l;
    private String tableTitle;
    private String tableName;
    private String data;
    private String aesKey;

    /**
     * 是否需要分页，默认为是
     */
    private boolean needPage = true;

    private Map<Search, String> search = new HashMap<>();

    private List<Map<Order, String>> order = new ArrayList<>();

    private List<Map<Column, String>> columns = new ArrayList<Map<Column, String>>();

    public enum Search {
        value,
        regex
    }

    public enum Order {
        column,
        dir
    }

    public enum Column {
        data,
        name,
        searchable,
        orderable,
        searchValue,
        searchRegex
    }


//    private Search search;
//    @JsonProperty("order")
//    private List<Order> order;
//
//    private List<Column> columns;

    public String getActiontype() {
        return actiontype;
    }

    public void setActiontype(String actiontype) {
        this.actiontype = actiontype;
    }

    public String getEnabled() {
        return enabled;
    }

    public void setEnabled(String enabled) {
        this.enabled = enabled;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getDraw() {
        return draw;
    }

    public void setDraw(int draw) {
        this.draw = draw;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getPageNum() {
//        this.pageNum = (this.start / this.length) + 1;
        return pageNum;
    }
    public String getOrderBy() {
        this.orderBy = "";
//        if (this.getSortcolumn() != null && !"".equals(this.getSortcolumn())) {
//            this.orderBy += this.sortcolumn;
//        }
//        if (this.sortorder != null && !"".equals(this.sortorder)) {
//            this.orderBy = this.orderBy + " " + this.sortorder;
//        }
        if (order != null && order.size() > 0) {
            int index;
            String colname;
            for (Map<Order, String> map : order) {//排序集合
                index = Integer.parseInt(map.get(Order.column));
                if (columns != null && columns.size() > 0) {
                    if (index >= 0 && index <= columns.size()) {
                        colname = columns.get(Integer.parseInt(map.get(Order.column))).get(Column.name);
                        if (colname != null && !colname.isEmpty()) {
                            orderBy += (orderBy.isEmpty() ? "" : ",")
                                    + colname + " " + map.get(Order.dir);
                        }
                    }
                } else {
                    break;
                }
            }
        }
        return orderBy;
    }

    public String getSortcolumn() {
        return sortcolumn;
    }

    public void setSortcolumn(String sortcolumn) {
        this.sortcolumn = sortcolumn;

    }

    public void setSortcolumn(String sortcolumn, String defult) {
        if (sortcolumn != null && !"".equals(sortcolumn)) {
            this.sortcolumn = sortcolumn;
        } else {
            this.sortcolumn = defult;
        }
    }


    public String getSortorder() {
        return sortorder;
    }

    public void setSortorder(String sortorder) {
        this.sortorder = sortorder;
    }

    public void setSortorder(String sortorder, String defult) {
        if (sortorder != null && !"".equals(sortorder)) {
            this.sortorder = sortorder;
        } else {
            this.sortorder = defult;
        }
    }

//    public Search getSearch() {
//        return search;
//    }
//
//    public void setSearch(Search search) {
//        this.search = search;
//    }
//
//    public List<Order> getOrder() {
//        return order;
//    }
//
//    public void setOrder(List<Order> order) {
//        this.order = order;
//    }
//
//    public List<Column> getColumns() {
//        return columns;
//    }
//
//    public void setColumns(List<Column> columns) {
//        this.columns = columns;
//    }


    public Map<Search, String> getSearch() {
        return search;
    }

    public void setSearch(Map<Search, String> search) {
        this.search = search;
    }

    public List<Map<Order, String>> getOrder() {
        return order;
    }

    public void setOrder(List<Map<Order, String>> order) {
        this.order = order;
    }

    public List<Map<Column, String>> getColumns() {
        return columns;
    }

    public void setColumns(List<Map<Column, String>> columns) {
        this.columns = columns;
    }

    public int getTotalOffset() {
        return totalOffset;
    }

    public void setTotalOffset(int totalOffset) {
        this.totalOffset = totalOffset;
    }

    public long getRecordTotal() {
        return recordTotal;
    }

    public void setRecordTotal(long recordTotal) {
        this.recordTotal = recordTotal;
    }

    public String getTableTitle() {
        return tableTitle;
    }

    public void setTableTitle(String tableTitle) {
        this.tableTitle = tableTitle;
    }

    public Boolean getCheckflag() {
        return checkflag;
    }

    public void setCheckflag(Boolean checkflag) {
        this.checkflag = checkflag;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    public boolean isNeedPage() {
        return needPage;
    }

    public void setNeedPage(boolean needPage) {
        this.needPage = needPage;
    }

}
